package main

import (
	"fmt"
	"math"
)

func main() {

	var a int = 20
	var b int = 30

	var ret int

	ret = max(a, b)

	fmt.Printf("最大值是 : %d\n", ret)

	c, d := swap("Google", "hello")

	fmt.Println(c, d)

	fmt.Printf("语言函数作为实参")

	getSquareRoot := func(x float64) float64 {
		return math.Sqrt(x)
	}

	/* 使用函数 */
	fmt.Println(getSquareRoot(9))

	fmt.Printf("以下是闭包：")

	nextNumber := getSequence()
	fmt.Println(nextNumber())
	fmt.Println(nextNumber())
	fmt.Println(nextNumber())

	nextNumber1 := getSequence()

	fmt.Println(nextNumber1())
	fmt.Println(nextNumber1())
}

func max(num1, num2 int) int {

	var result int

	if num1 > num2 {
		result = num1
	} else {
		result = num2
	}

	return result

}

func swap(x, y string) (string, string) {
	return y, x
}

func getSequence() func() int {
	i := 0
	return func() int {
		i += 1
		return i
	}
}
